package net.csdra;

import net.csdra.basis.domain.UserBaseInterface;
import net.csdra.user.domain.User;
import org.springframework.security.access.PermissionEvaluator;
import org.springframework.security.core.Authentication;
import org.springframework.stereotype.Component;

import java.io.Serializable;

/**
 * Created by msf on 2018/1/23.
 */
@Component
public class PermissionHandle implements PermissionEvaluator {
    @Override
    public boolean hasPermission(Authentication authentication, Object currentMetaId, Object permissionType) {
        return false;
    }

    @Override
    public boolean hasPermission(Authentication authentication, Serializable targetId, String targetType, Object permissionType) {
        if (permissionType instanceof String) {
            User credentials = (User) authentication.getCredentials();
            if ("metaId".equals(targetType) && "isManage".equals(permissionType)) {
                return credentials.getMetaId().equals(targetId);
            }
            if ("id".equals(targetType)) {

            }

        }
        return false;
    }

//    private boolean check(PermissionType permissionType) {
//        switch (permissionType) {
//            case currentDistrictUser:
//                break;
//            case customizeDistrictUser:
//                break;
//
//            default:
//                return false;
//        }
//
//    }
}
